package com.kejiguan.ui.presenter;

import android.content.Context;
import android.widget.Toast;

import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.TakeAllOffResponse;
import com.kejiguan.ui.response.TakeAllOnResponse;
import com.kejiguan.ui.util.CacheDataUtil;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by apple on 16/3/31.
 */
public class EasyShuttlePresenter extends BaseFragmentPresenter{



    public void takeAllOff(final Context context)
    {

        long currentTime=System.currentTimeMillis();
        String currentDate=String.valueOf(currentTime);
        try {
            currentDate= DateFormatUtil.longToString(currentTime,"yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String,String> params=new HashMap<>();
        params.put("requestCode","701");
        params.put("messageId",currentDate+"S"+currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("userName", CacheDataUtil.getInstance().getmUser().getUserName());
        params.put("actionFlag","G");
        params.put("deviceFlag","Z");
        params.put("deviceId","ALL");




        final GsonRequest<TakeAllOffResponse> request = new GsonRequest("TakeAllOff", TakeAllOffResponse.class, new Response.Listener<TakeAllOffResponse>() {
            @Override
            public void onResponse(TakeAllOffResponse response) {

                EventBus.getDefault().post(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Toast.makeText(context,"关机消息发送失败",Toast.LENGTH_SHORT).show();

            }
        });

        RequestUtil.sendRequest(context, params, request);
    }

    public void takeAllOn(final Context context)
    {
        long currentTime=System.currentTimeMillis();
        String currentDate=String.valueOf(currentTime);
        try {
            currentDate= DateFormatUtil.longToString(currentTime,"yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String,String> params=new HashMap<>();
        params.put("requestCode","701");
        params.put("messageId",currentDate+"S"+currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("userName", CacheDataUtil.getInstance().getmUser().getUserName());
        params.put("actionFlag","K");
        params.put("deviceFlag","Z");
        params.put("deviceId","ALL");



        final GsonRequest<TakeAllOnResponse> request = new GsonRequest("TakeAllOn", TakeAllOnResponse.class, new Response.Listener<TakeAllOnResponse>() {
            @Override
            public void onResponse(TakeAllOnResponse response) {
                EventBus.getDefault().post(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context,"开机消息发送失败",Toast.LENGTH_SHORT).show();
            }
        });

        RequestUtil.sendRequest(context, params, request);
    }

}
